package com.example.service;


import com.example.service.impl.HelloWorldImpl;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

import java.net.InetAddress;

/**
 * 访问地址 http://192.168.146.1/helloWorld?wsdl
 * 必须加?wsdl，如果仅http://192.168.146.1/helloWorld  服务端会报如下错误
 * org.apache.cxf.interceptor.Fault: No binding operation info while invoking unknown method with params unknown.
 */
public class CXFServer {

    public static void main(String[] args) throws Exception {
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        System.out.println("本机局域网IP地址为："+hostAddress);

        System.out.println("WebService starting!");
        HelloWorld implementor = new HelloWorldImpl();
        JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean();
        String address = "http://"+hostAddress+"/helloWorld";
        factoryBean.setAddress(address); // 设置暴露地址
        factoryBean.setServiceClass(HelloWorld.class); // 接口类
        factoryBean.setServiceBean(implementor); // 设置实现类
        factoryBean.create();
        System.out.println("WebService started!");
    }

}
